import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query, UseGuards } from "@nestjs/common";
import { MyApi } from "../modules/action/descriptor/function.descriptoor";
import { MyController } from "../modules/action/descriptor/http.decorator";
import { JwtAuthGuard } from "../modules/auth/guard/jwt-auth.guard";
import { MenuEntity } from "../Entity/menu.entity";
import { MenuService } from "../service/menu.service";

@UseGuards(JwtAuthGuard)
@MyController('MenuController')
@Controller('menu')
export class MenuController {
    constructor(private readonly menuService: MenuService) { }

    @Post()
    @MyApi("添加一条菜单信息")
    addUser(@Body() menuEntity: MenuEntity) {
        return this.menuService.create(menuEntity);
    }

    @Get()
    @MyApi("查询所有菜单信息")
    async findAll(){
        return this.menuService.findAll();
    }

    @Get(':id')
    @MyApi("根据id查询特定菜单信息")
    async findOne(@Param('id',ParseIntPipe) id: number) {
        return this.menuService.findOne(id);
    }

    @Delete(':id')
    @MyApi("根据id删除菜单信息")
    async deleteById(@Param('id',ParseIntPipe) id: number) {
        return this.menuService.remove(id);
    }

    @Put()
    @MyApi("修改一条菜单信息")
    async updateUser(@Body() menuEntity: MenuEntity) {
        return this.menuService.update(menuEntity);
    }

}